import {messages} from "share/common";
import React from 'react'
import { connect } from 'react-redux'
import { Form } from 'antd'

import moment from 'moment'
import 'styles/request/travel-request/travel-date.scss'

class TravelDate extends React.Component{
  constructor(props) {
    super(props);
    this.state = {}
  }

  //获取天数差
  getDifferDays = (sDate, eDate) => {
    sDate = new Date(new Date(sDate).format('yyyy-MM-dd'));
    eDate = new Date(new Date(eDate).format('yyyy-MM-dd'));
    return Math.abs(Math.floor((eDate - sDate)/1000/60/60/24)) + 1
  };

  render() {
    const { info, isLeft } = this.props;
    let sDate = info.travelApplication && info.travelApplication.startDate;
    let eDate = info.travelApplication && info.travelApplication.endDate;
    return (
      <div className={`travel-date ${isLeft ? 'travel-date-no-left' : ''}`}>
        {messages('request.key314'/*出差日期*/)}：
        {moment(sDate).format('YYYY-MM-DD')} ～ {moment(eDate).format('YYYY-MM-DD')}，
        {messages('request.key461',{arg1: this.getDifferDays(sDate,eDate) || 0}/*共{arg1}天*/)}
      </div>
    )
  }
}

TravelDate.propTypes = {
  info: React.PropTypes.object,
  isLeft: React.PropTypes.bool //是否是最左边的块，true时去除margin-left
};

TravelDate.defaultProps={
  info: {},
  isLeft: false
};

function mapStateToProps() {
  return {}
}

const wrappedLoanRepayment = Form.create()(TravelDate);

export default connect(mapStateToProps)(wrappedLoanRepayment)
